package com.KeyWord.equals_.Exercise;

public class Exercise__ {
    public static void main(String[] args) {
        Person1 p1 = new Person1();
        p1.name = "John";

        Person1 p2 = new Person1();
        p2.name = "John";

        System.out.println(p1 == p2);//比较地址，false
        System.out.println(p1.name.equals(p2.name));//比较姓名的地址,在常量池中是同一个地址  true
        System.out.println(p1.equals(p2));//比较两个对象的地址  false

        String s1 = new String("asdf");

        String s2 = new String("asdf");

        System.out.println(s1 == s2);//比较的是两个对象的地址， false
        System.out.println(s1.equals(s2));//比较的是两个对象的值, true



    }
}

class Person1 {
    public String name;
}


